package graph

import "github.com/hwcer/cosgo/values"

type Relation uint8

const (
	RelationNone       Relation = 0      //无关系，但可能有互动
	RelationFans       Relation = 1      //我的粉丝
	RelationFollow     Relation = 1 << 1 //我的关注
	RelationFriend     Relation = 1 << 2 //我的好友
	RelationSpouse     Relation = 1 << 3 //夫妻
	RelationMaster     Relation = 1 << 4 //我师傅
	RelationApprentice Relation = 1 << 5 //我徒弟
	RelationUnfriend   Relation = 1 << 7 //黑名单
)

func (r Relation) Has(v Relation) bool {
	return r&v == v
}

func (r Relation) Set(v Relation) Relation {
	if r&v == v {
		return r
	}
	return r | v
}

type Factory interface {
	Create(uid string) (values.Values, error)
	SendMessage(uid string, path string, data any)
}

type Getter struct {
	sg  *Graph
	fid string
	fri *Friend
}

func (this *Getter) Fid() string {
	return this.fid
}

func (this *Getter) Player() *Player {
	return this.sg.nodes[this.fid]
}
func (this *Getter) Friend() *Friend {
	return this.fri
}

// Statement 通过Lock RLock 获得的临时无锁操作
type Statement struct {
	g *Graph
}

func (this *Statement) Get(uid string) *Player {
	return this.g.nodes[uid]
}

/*
// /////////////////////////////////////////////////////////////////////////
type Apply map[string]int64

func (this Apply) Has(id string) bool {
	_, ok := this[id]
	return ok
}

func (this Apply) Add(id string) {
	this[id] = time.Now().Unix()
}
func (this Apply) Delete(id string) {
	delete(this, id)
}
func (this Apply) Clone() Apply {
	r := make(Apply, len(this))
	for k, v := range this {
		r[k] = v
	}
	return r

}

// /////////////////////////////////////////////////////////////////////////

type Relation map[string]*Friend

func (this Relation) Has(id string) bool {
	_, ok := this[id]
	return ok
}
func (this Relation) Add(fd string, value *Friend) {
	this[fd] = value
}
func (this Relation) Delete(id string) {
	delete(this, id)
}
func (this Relation) Clone() Relation {
	r := make(Relation, len(this))
	for k, v := range this {
		r[k] = v
	}
	return r

}

type Getter struct {
	vs values.Values
}

func (vs *Getter) Has(k string) bool {
	return vs.vs.Has(k)
}

func (vs *Getter) Friend(k string) any {
	return vs.vs.Friend(k)
}

func (vs *Getter) GetInt(k string) int {
	return vs.vs.GetInt(k)
}

func (vs *Getter) GetInt32(k string) int32 {
	return vs.vs.GetInt32(k)
}

func (vs *Getter) GetInt64(k string) int64 {
	return vs.vs.GetInt64(k)
}

func (vs *Getter) GetFloat32(k string) float32 {
	return vs.vs.GetFloat32(k)
}

func (vs *Getter) GetFloat64(k string) (r float64) {
	return vs.vs.GetFloat64(k)
}
func (vs *Getter) GetString(k string) (r string) {
	return vs.vs.GetString(k)
}
*/
